package com.wangyukai.jmonitor;

import com.alibaba.fastjson.JSON;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.List;

public class Config {
    public static  List<ServerConfig> serverinfo;
    private static Logger logger = LoggerFactory.getLogger(Config.class);

    public static void init(){
        try( BufferedReader reader = new BufferedReader(new InputStreamReader(Config.class.getClassLoader().
                getResourceAsStream("server.json"), "UTF-8"))){

            String line;
            StringBuilder result = new StringBuilder();
            while ((line = reader.readLine()) != null) {
                result.append(line);
            }

            serverinfo = JSON.parseArray(result.toString(), ServerConfig.class);
        }catch(Exception ex){
            logger.error("配置文件读取失败", ex);
        }
    }

}
